package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicLinePrice;
import cn.stylefeng.guns.modular.basic.mapper.BasicLinePriceMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicLinePriceParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicLinePriceResult;
import  cn.stylefeng.guns.modular.basic.service.BasicLinePriceService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 承运报价表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2021-07-29
 */
@Service
public class BasicLinePriceServiceImpl extends ServiceImpl<BasicLinePriceMapper, BasicLinePrice> implements BasicLinePriceService {

    @Override
    public void add(BasicLinePriceParam param){
        BasicLinePrice entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicLinePriceParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicLinePriceParam param){
        BasicLinePrice oldEntity = getOldEntity(param);
        BasicLinePrice newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicLinePriceResult findBySpec(BasicLinePriceParam param){
        return null;
    }

    @Override
    public List<BasicLinePriceResult> findListBySpec(BasicLinePriceParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicLinePriceParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<BasicLinePriceResult> getlineprice(BasicLinePriceParam param) {
        return this.baseMapper.getlineprice(param);
    }

    @Override
    public List<BasicLinePriceResult> getCarrierNulllineprice(BasicLinePriceParam param) {
        return this.baseMapper.getCarrierNulllineprice(param);
    }


    private Serializable getKey(BasicLinePriceParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicLinePrice getOldEntity(BasicLinePriceParam param) {
        return this.getById(getKey(param));
    }

    private BasicLinePrice getEntity(BasicLinePriceParam param) {
        BasicLinePrice entity = new BasicLinePrice();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
